import request from "@/utils/request";
import { API_ENDPOINTS } from "@/config/api";

// 成就接口
export interface Achievement {
  id: number;
  title: string;
  name?: string; // 保持向后兼容
  description: string;
  icon_url?: string;
  points: number;
  rarity?: "common" | "rare" | "epic" | "legendary";
  is_unlocked: boolean;
  is_featured?: boolean;
  category_id?: number;
  unlocked_at?: string;
  progress?: {
    current: number;
    target: number;
  };
  requirements?: string[];
  badge_url?: string;
}

// 用户成就接口
export interface UserAchievement {
  id: number;
  achievement_id: number;
  user_id: number;
  earned_at: string;
  achievement: Achievement;
}

// 成就相关API
export const achievementApi = {
  // 获取成就列表
  getAchievements() {
    return request.get<Achievement[]>(API_ENDPOINTS.ACHIEVEMENTS.LIST);
  },

  // 获取用户成就
  getUserAchievements(userId: number) {
    return request.get<UserAchievement[]>(
      API_ENDPOINTS.ACHIEVEMENTS.USER_ACHIEVEMENTS(userId)
    );
  },

  // 检查成就进度
  checkAchievements(userId: number) {
    return request.post(API_ENDPOINTS.ACHIEVEMENTS.CHECK(userId));
  },
};
